home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createBrushPresetScript.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.1 KB  |  156 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. proc string processString( string $inputStr )
  18. //
  19. //    Description:
  20. //        This proc will process the input string for output as an
  21. //        arg in a "bPset" command.
  22. //        Mainly, this proc changes all occurrences of carriage
  23. //        returns and line feeds to "\r" and "\n" respectively.
  24. //
  25. {
  26.     string $attr = $inputStr;
  27.     
  28.     // Use "substitute" repeatedly until there are no more 
  29.     // substitutions.
  30.     //
  31.     int $numChecks = size($attr);
  32.     int $i = 0;
  33.     for( ; $i < $numChecks; $i ++ ) {
  34.         string $tmp  = `substitute "\n" $attr "\\n"`;
  35.         $tmp  = `substitute "\r" $tmp "\\r"`;
  36.         if( $tmp == $attr ) {
  37.              break;     // no more substitutions necessary
  38.         } else {
  39.             $attr = $tmp;
  40.             // there were some substitutions here, 
  41.             // so keep trying to substitute
  42.         }
  43.     }
  44.     $attr = `substituteAllString $attr "\"" "\\\""`;
  45.     $attr = `substituteAllString $attr "\'" "\\\'"`;
  46.     return $attr;
  47. }
  48.  
  49. proc string getNodeValues(string $nodeName)
  50. {
  51.     int $mode = 0;
  52.     float $scalefac;
  53.     string $atrs[] = `listAttr -k -w -s -m $nodeName`;
  54.     string $atr;
  55.     string $reslt = "brushPresetSetup();";
  56.     // Set up the pre-set so that it will create the default brush if it doesn't exist.
  57.  
  58.     // Loop through the attributes. If we find any with connections, check if they are to
  59.     // an anim node, if so, we will try to create a script to recreate that node and connection.
  60.     for ($atr in $atrs) 
  61.     {
  62.         string $objName = $nodeName +"." + $atr;
  63.         if( !objExists( $objName )){
  64.             continue;
  65.         }
  66.         if ( `connectionInfo -isDestination ($objName)` ) {
  67.             // It is a destination of a connection.
  68.             // This section of the code assumes that it is alright to break up the bPset() calls.
  69.             // Get all nodes connected to this brush attr "$nodeName.atr"
  70.             string $connections[] = `listConnections $objName`;
  71.             // Get the name of the attribute on the source node.
  72.             string $sourceAttr = `connectionInfo -sfd $objName`;
  73.             // Clip off just the attribute name of sourceAttr.
  74.             string $buffer[];
  75.             int $num = `tokenize $sourceAttr "." $buffer`;
  76.             $sourceAttr = $buffer[$num-1];
  77.             string $connection;
  78.  
  79.             // For every node connected to this attribute.
  80.             for ($connection in $connections) {
  81.                 if (`nodeType $connection` != "time") { // Do not attempt to duplicate the time node. 
  82.                     if (isAnimCurve( $connection )) {
  83.                         string $animCommands[] = `getCopyAnimCurveCommands( $connection )`;
  84.                         string $animCommand;
  85.                         for ($animCommand in $animCommands) {
  86.                             $reslt = $reslt + $animCommand;
  87.                         }
  88.                         // Finally, add script to connect the newly created to the proper attribute.
  89.                         $reslt = $reslt + "bPsetNewNodeName( $animCurve ); ";
  90.                         $reslt = $reslt + "bPsetConnect( \"" + $sourceAttr + "\", \"" + $atr + "\");";
  91.                     }
  92.                     // else, it is not an anim curve. Ignore it for the time being.
  93.                     // Find all writable, multi, scalar attributes on this node.
  94.                     //    string $lAtrs[] = `listAttr -multi -write -scalar $connection`;
  95.                     //    string $lAtr;
  96.                     //    for ($lAtr in $lAtrs) {
  97.                     //        // For each attribute found, create a script which will recreate the attribute's settings.
  98.                     //        string $gAtr = "getAttr " + $connection +"." + $lAtr;
  99.                     //        $reslt = $reslt + "setAttr (bPNewNodeName() + \"." + $lAtr + "\") " + eval($gAtr) + ";";
  100.                     //    }
  101.                 }
  102.             }
  103.         } else {
  104.             // No connection, just do a setAttr.
  105.             string $gAtr = "getAttr " + $objName;
  106.             $reslt = $reslt + "bPset \"" + $atr + "\" " + eval($gAtr) + "; ";
  107.         }
  108.     }
  109.     $reslt = $reslt + "\nbPsetName \"imageName\" \"" + `getAttr ($nodeName +".imageName")` + "\";\n";
  110.     $reslt = $reslt + "bPsetName \"leafImage\" \"" + `getAttr ($nodeName +".leafImage")` + "\";\n";
  111.     $reslt = $reslt + "bPsetName \"flowerImage\" \"" + `getAttr ($nodeName +".flowerImage")` + "\";\n";
  112.     $reslt = $reslt + "bPsetName \"creationScript\" \"" + `getAttr ($nodeName +".creationScript")` + "\";\n";
  113.     $reslt = $reslt + "bPsetName \"runtimeScript\" \"" + `getAttr ($nodeName +".runtimeScript")` + "\";\n";
  114.     if( objExists($nodeName +".notes") ) {
  115.         string $str = `getAttr ($nodeName +".notes")`;
  116.         $str = processString( $str );
  117.         $reslt = $reslt + "bPsetNotes \"notes\" \"" + $str + "\";\n";
  118.     }
  119.     $reslt = $reslt + "brushPresetApply();";
  120.  
  121.     return $reslt;
  122. }
  123.  
  124. proc string getPressureSettings()
  125. {
  126.     global string $gCreatorWireCtx;
  127.     string $whichCtx = $gCreatorWireCtx;
  128.  
  129.     int $mapping = `dynWireCtx -q -pm1 $whichCtx`;
  130.     float $min   = `dynWireCtx -q -ps1 $whichCtx`;
  131.     float $max   = `dynWireCtx -q -px1 $whichCtx`;
  132.     string $str = ("presetSetPressure 1 " + $mapping + " " + $min + " " + $max + ";\n");
  133.  
  134.     int $mapping = `dynWireCtx -q -pm2 $whichCtx`;
  135.     float $min   = `dynWireCtx -q -ps2 $whichCtx`;
  136.     float $max   = `dynWireCtx -q -px2 $whichCtx`;
  137.     $str = $str + ("presetSetPressure 2 " + $mapping + " " + $min + " " + $max + ";\n");
  138.  
  139.     int $mapping = `dynWireCtx -q -pm3 $whichCtx`;
  140.     float $min   = `dynWireCtx -q -ps3 $whichCtx`;
  141.     float $max   = `dynWireCtx -q -px3 $whichCtx`;
  142.     $str = $str + ("presetSetPressure 3 " + $mapping + " " + $min + " " + $max + ";\n");
  143.  
  144.     return $str;
  145.     
  146. }
  147.  
  148.  
  149. global proc string createBrushPresetScript( string $brushName )
  150. {
  151.     // Create a command for this button
  152.     string $shelfCommand = `getNodeValues $brushName`;
  153.     $shelfCommand = $shelfCommand + "\n" +getPressureSettings();
  154.     return $shelfCommand;
  155. }
  156.